package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.chenfeng.vo.BrandListVo;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信端品牌制造商的controller
 *
 * @author Chen_Feng
 * @since 2022/06/29 12:55
 */
@RestController("wxBrandController")
@RequestMapping("wx/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    /**
     * 获取品牌商的列表
     *
     * @return com.cskaoyan.bean.BaseRespVo<com.cskaoyan.bean.chenfeng.vo.BrandListVo>
     * @author Chen_Feng
     * @since 2022/06/29 13:02
     */
    @RequestMapping("list")
    public BaseRespVo<BrandListVo> list(Integer page, Integer limit) {

        // 执行查询业务
        CommonData<BrandListVo> data = null;
        try {
            data = brandService.getBrandListByPage(page, limit);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("获取数据异常");
        }

        return BaseRespVo.ok(data);
    }

    /**
     * 获取品牌制造商详细信息
     *
     * @param id 品牌制造商的id
     * @return com.cskaoyan.bean.BaseRespVo<com.cskaoyan.bean.chenfeng.vo.BrandListVo>
     * @author Chen_Feng
     * @since 2022/06/29 13:18
     */
    @RequestMapping("detail")
    public BaseRespVo<MarketBrand> detail(Integer id) {

        // 参数校验
        if (id == null) {
            return BaseRespVo.invalidParameter("参数错误");
        }

        // 执行业务
        try {
            MarketBrand data = brandService.getBrandDetailByBrandId(id);
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("没有获取到数据哦");
        }
    }
}
